package com.run2code.design.behavioral.iterator;

import com.run2code.design.behavioral.iterator.base.Iterable;
import com.run2code.design.behavioral.iterator.base.Iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 组织类
 * 实现Iterable接口的iterator()方法，返回一个Iterator实例
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2024/01/30
 */
public class Organization implements Iterable<Employee> {
    private List<Employee> employees;

    public Organization() {
        employees = new ArrayList<>();
    }

    public void addEmployee(Employee employee) {
        employees.add(employee);
    }

    @Override
    public Iterator<Employee> iterator() {
        return new OrganizationIterator(employees);
    }

}
